package com.tianji.remark.task;

import cn.hutool.core.collection.CollUtil;
import com.tianji.common.autoconfigure.mq.RabbitMqHelper;
import com.tianji.common.constants.CacheConstant;
import com.tianji.common.domain.dto.LikedTimesDTO;
import com.tianji.remark.domain.po.LikedRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Slf4j
//@Component
public class LikeRecordSyncToMysqlTask {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private RabbitMqHelper mqHelper;


    @Scheduled(cron = "*/10 * * * * ?")
    public void likeRecordSyncToMysql(){
        while (true){
            Set<ZSetOperations.TypedTuple<String>> typedTuples = redisTemplate.opsForZSet().popMax(CacheConstant.LIKE_COUNT, 100);
            if(CollUtil.isEmpty(typedTuples)){
                log.info("没有要同步的数据");
                return;
            }
            List<LikedTimesDTO> msgList = new ArrayList<>();
            for (ZSetOperations.TypedTuple<String> typedTuple : typedTuples) {
                Double score = typedTuple.getScore();
                String value = typedTuple.getValue();
                String[] arr = value.split(":");
                String bizType = arr[0];
                String bizId = arr[1];
//                new LikedTimesDTO()
            }
        }
    }
}
